package top.hmtools.services;

import java.util.Collection;

import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.Logger;
import org.apache.logging.log4j.core.LoggerContext;
import org.springframework.stereotype.Service;

/**
 * 日志服务工具
 * @author HyboJ
 *
 */
@Service
public class LoggerService extends BaseService{

	/**
	 * 更改当前工程运行时日志级别
	 * @param level
	 */
	public void changeLogLevel(Level level){
		Collection<Logger> notCurrentLoggerCollection = LoggerContext.getContext(false).getLoggers();
		Collection<Logger> currentLoggerCollection = LoggerContext.getContext().getLoggers();
		Collection<Logger> loggerCollection = notCurrentLoggerCollection;
		loggerCollection.addAll(currentLoggerCollection);  
        for (Logger logger:loggerCollection){  
            logger.setLevel(level);  
        }  
	}
	
	/**
	 * 改变日志级别为debug
	 */
	public void changeLogLevelDebug(){
		this.changeLogLevel(Level.DEBUG);
	}
}
